package com.fanqiechaodan.facade;

/**
 * @author fanqiechaodan
 * @Classname OnlineShoppingFaced
 * @Description 门面类
 */
public class OnlineShoppingFacade {

    private InventoryManagement inventoryManagement;
    private OrderManagement orderManagement;
    private PaymentManagement paymentManagement;

    public OnlineShoppingFacade(InventoryManagement inventoryManagement, OrderManagement orderManagement, PaymentManagement paymentManagement) {
        this.inventoryManagement = inventoryManagement;
        this.orderManagement = orderManagement;
        this.paymentManagement = paymentManagement;
    }

    /**
     * 下单操作
     *
     * @param itemId
     * @param quantity
     * @param paymentMenthod
     */
    public void placeOrder(String itemId, int quantity, String paymentMenthod) {
        System.out.println("开始处理下单操作...");
        boolean checkInventory = inventoryManagement.checkInventory(itemId, quantity);
        if (!checkInventory) {
            throw new RuntimeException("库存不足");
        }
        Order order = orderManagement.createOrder(itemId, quantity);
        paymentManagement.makePayment(order, paymentMenthod);
    }
}
